﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.FarmEnterprises
{
    public class FarmUpdRequestHandler : IRequestHandler<FarmUpdRequestModel, APIResult>
    {
        private IBaseRepository<FarmEnterprise> farmdRepository;
        private readonly IMapper mapper;
        public FarmUpdRequestHandler(IBaseRepository<FarmEnterprise> farmdRepository, IMapper mapper)
        {
            this.farmdRepository = farmdRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(FarmUpdRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.UpdSuccess;
            result.Msg = "编辑成功";

            FarmEnterprise farm = mapper.Map<FarmEnterprise>(request);
            farmdRepository.Update(farm);

            return Task.FromResult(result);
        }
    }
    public class FarmUpdRequestModel: IRequest<APIResult>
    {
        public int Id { get; set; }
        public string ProductCode { get; set; }
        /// <summary>
        /// 养殖场
        /// </summary>
        public string Farm { get; set; }
        /// <summary>
        /// 负责人
        /// </summary>
        public string Custodian { get; set; }
        /// <summary>
        /// 存栏数量
        /// </summary>
        public int FeedNum { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
    }
}



